﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Light.Framework.Contract;
using Light.Framework.Model;
using Light.Framework.Castle;
using NHibernate.Criterion;
using Light.Utility;

namespace Light.Framework.Component
{
    /// <summary>
    /// 日志组件
    /// </summary>
    public class LogComponent : BaseComponent<Log>, ILogComponent
    {

        #region ILogComponent 成员

        public IList<Log> Search(SearchArgs args, int pageIndex, int pageSize, out int totalResult, LogType type)
        {
            DetachedCriteria dc = base.GetDetachedCriteria(args);
            dc.Add(Expression.Eq("LogType", type));
            dc.Add(Expression.Eq("IsDeleted", false));

            return base.Search(dc, pageIndex, pageSize, out totalResult);
        }

        public override OperateResult Delete(IList<Log> models)
        {
            OperateResult result = base.Delete(models);
            if (result.IsSucced)
            {
                ServerApplication.Logger.LogOperation("用户【" + ServerApplication.User.Name + "】清空【" + EnumHelper.GetEnumDesc(models[0].LogType) + "日志】");
            }
            return result;
        }

        #endregion
    }
}
